<script>
import axios from "axios";
import CarouselMap from "@/components/dialog/CarouselMap.vue";

export default {
  name: "homePhoto",
  components: {CarouselMap},
  data() {
    return {
      album_list: [{
        id: 0,
        name: "",
        cover: "",
        count: 0
      }],
      album_loading:false,
      album_name:"",
      album_id:"",
      carousel_map:false
    }
  },
  methods: {
    getAlbumList() {
      this.album_loading = true
      axios.get(`/api/album/list/0`)
          .then(res => {
            if (res.data.code === 0) {
              this.album_loading = false
              this.album_list = res.data.data
            } else {
              this.$message.warning(res.data.msg)
            }
          }).catch(err => this.$message.error(err))
    },
    getAlbumDetail(index) {
      if (this.album_list[index].count === 0) {
        this.$message.info("这是一个空空相册")
      } else {
        this.album_name = this.album_list[index].name
        this.album_id = this.album_list[index].id
        this.carousel_map = true
      }
    },
  },
  mounted() {
    this.getAlbumList()
  }
}
</script>

<template>
  <div>
    <div class="carousel">
      <el-dialog :visible.sync="carousel_map" :title="'《'+album_name+'》'" top="3vh" width="80%" destroy-on-close
                 @close="album_id='';album_name=''" append-to-body>
        <carousel-map :id="album_id"></carousel-map>
      </el-dialog>
    </div>

    <div class="p_pic_box" v-loading="album_loading">
      <el-card class="pic_card" shadow="hover" v-for="(item,index) in album_list" :key="index"
               @click.native="getAlbumDetail(index)">
        <div class="pic_card_img_box">
          <img alt="" :src="item.cover!==''?item.cover:require('@/assets/img/无图片.png')"/>
          <div class="mask">
            <div class="pic_zs">{{ item.count }}</div>
          </div>
        </div>
        {{ item.name }}<i v-show="item.status === 1" class="el-icon-lock"
                          style="font-size: 18px;color: #409EFF;margin-left: 5px"></i>
      </el-card>
      <h1 v-show="album_list.length === 0" style="margin-left: 20px;color: #cdcdcd">用户未上传照片</h1>
    </div>
  </div>

</template>

<style scoped>
.p_pic_box {
  height: 400px;
  overflow: auto;
}
.pic_card {
  margin-top: 20px;
  float: left;
  margin-left: 25px;
  height: 215px;
  width: 200px;

  text-align: center;
}

.pic_card_img_box {
  position: relative;
  display: flex;
  justify-content: center;
  align-items: center;
  text-align: center;
  margin-bottom: 5px;
  height: 160px;
  width: 160px;

  .mask {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    cursor: pointer;
    background-image: linear-gradient(to bottom right, transparent, rgba(0, 0, 0, 0.82));
  }
}
</style>